<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="cc.woori.mobile.bean.*" %>
<%@ page import="cc.woori.mobile.PMF" %>
<%@ page import="javax.jdo.*" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form name="input" action="/admin/register" method="post">
    <table>
      <tr>
        <td>설교제목</td>
        <td><input type="text" name="title" size="80"/></td>
      </tr>
      <tr>
        <td>본문말씀</td>
        <td><input type="text" name="verse" size="80"/></td>
      </tr>
      <tr>
        <td>설명</td>
        <td><TEXTAREA name="description" rows="5" cols="50"></TEXTAREA></td>
      </tr>
      <tr>
        <td>목사님 성함</td>
        <td><input type="text" name="pastorName" value="김양재"size="80"/></td>
      </tr>
      <!-- 
      <tr>
        <td>설교사진 URL</td>
        <td><input type="text" name="servicePic" /></td>
      </tr>
       -->
      <tr>
        <td>설교 동영상 URL</td>
        <td><input type="text" name="videoUrl" size="80"/></td>
      </tr>
      
      <tr>
        <td>설교 오디오 URL</td>
        <td><input type="text" name="audioUrl" size="80"/></td>
      </tr>
	  <tr>
        <td>설교 길이</td>
        <td><input type="text" name="length" size="8"/>(HH:MM:SS, H:MM:SS, MM:SS, or M:SS 이런 포멧이여야 합니다.)</td>
      </tr>
      <tr>
        <td>날짜</td>
        <td><input type="text" name="date" size="80"/>(예. 20100719)</td>
      </tr>
      <tr>
      	<td><input type="submit" value="등록" /></td>
      </tr>
    </table>
    </form>
    
    
	<table>
    <tr>
    	<th>제목(목사님 성함)</th>
    	<th>본문말씀</th>
    	<th>날짜</th>
    	<th>동영상URL</th>
    	<th>오디오URL</th>
    	<th>수정</th>
    	<th>삭제</th>
    </tr>
    <%
    
    PersistenceManager pm = PMF.get().getPersistenceManager();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    
    try{
    	
		Query query = pm.newQuery(ChurchServiceEntry2.class);
		query.setOrdering("publishDate desc");
		query.setRange(0,30);
		
		List<ChurchServiceEntry2> results = (List<ChurchServiceEntry2>) query.execute();

	    for (ChurchServiceEntry2 e : results) {
	    %>
	    	<tr>
	    		<td>
	    			<!-- 제목 (목사님 이름) -->
	    			<%=e.getTitle()%> (<%=e.getPastor()%>)
	    		</td>
	    		<td>
	    			<!-- 본문말씀 -->
	    			<%=e.getVerse() %>
	    		</td>
	    		<td>
	    			<!-- 날짜 -->
	    			<%=sdf.format(e.getPublishDate())%>
	    		</td>
	    		<td>
	    			<!-- 설교 동영상 URL -->
	    			<%=e.getSvcVideoUrl()%>
	    		</td>
	    		<td>
	    			<!-- 설교 오디오 URL -->
	    			<%=e.getSvcAudioUrl()%>
	    		</td>
	    		<td>
	    			<a href="/admin/modifyService.jsp?key=<%=KeyFactory.keyToString(e.getKey()) %>">수정</a>
	    		</td>
	    		<td>
	    			<a href="/admin/modify?mode=delete&key=<%=KeyFactory.keyToString(e.getKey()) %>">삭제</a>
	    		</td>
	    	</tr>
	<%
	    }//end for
	}finally{
		if(pm != null){
			pm.close();
		}
	}
    %>
    </table>
	

</body>
</html>